﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddAttach.aspx.cs" Inherits="ZX.WebApp.AddAttach" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.upload.js" type="text/javascript"></script>
    <script src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script>
    <script src="../../Scripts/yui_2.9.0/build/json/json-min.js" type="text/javascript"></script>
    <script src="../../Scripts/yui_2.9.0/build/connection/connection-min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td class='label'>
                    <label id="lblUpload">
                        上传资料：<span style="color:Red;">*</span></label>
                </td>
                <td>
                    <div>
                        <input id="Address" name="Address" type="text" class="yui-upload"
                            readonly="readonly"
                            value="选择附件..." OnFocus="javascript:if(this.value=='选择附件...') {this.value=''}"
                            OnBlur="javascript:if(this.value==''){this.value='选择附件...'}"
                            style="width: 220px;" /></div>
                </td>
            </tr>
            <tr>
                <td>
                   <label id="lblExplain">
                        说明：</label> 
                </td>
                <td>
                    <textarea id="Explain" name="Explain" style="width:220px; height:100px;"></textarea>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    文件最大允许：50M
                </td>
            </tr>
        </table>
        <input type="hidden" id="Size" />
        <input type="hidden" id="Caption" />
    </div>
    </form>
    <form id="form2" style="display: none" action="../Extend/AjaxData/CustomOperating.aspx">
        <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    </form>
</body>
<script type="text/javascript">
    var url = "../Extend/AjaxData/CustomOperating.aspx";
    var instance = [{ "Caption": "", "Size": "", "Address": "", "Explain": ""}];
    var CustomerId = "<%=CustomerId %>";

    $(document).ready(function () {
        $('#Address').upload();
    });

    function FileSize(filesize) {
        alert("您选择的文件为 " + filesize + "M, 文件过大请重新上传!");
        return;
    }

    function setValue() {
        instance[0].Caption = $('#Caption').val();
        instance[0].Size = $('#Size').val();
        instance[0].Address = $('#Address').val();
        instance[0].Explain = $('#Explain').val();
    }

    function SaveAttach() {
        setValue();
        if ($('#Caption').val() == "") {
            alert("文件不能为空!");
            return;
        } else {
            var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
            $("#jsonDataContent").val(json);
            trySave();
        }
    }
    var trySave = function () {
        var formObject = document.getElementById('form2');
        YAHOO.util.Connect.setForm(formObject);
        var cObj = YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=procedure&entity=CrmCustomerAttach&id=" + CustomerId, callback);
    }
    var responseSuccess = function (res) {
        try {
            var str = res.responseText;
            if (str == "1") {
                alert("附件保存成功");
                location.reload(false);
                parent.LoadAttach();
            }
            else {
                alert(str);
            }
        } catch (e) {
        }
        finally {
        }
    };
    var responseFailure = function (error) {
        alert("数据错误：" + error.statusText);
    }
    var callback = {
        success: responseSuccess,
        failure: responseFailure
    };
</script>
</html>
